package com.sciencep.pro.core.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sciencep.pro.common.config.Constant;
import com.sciencep.pro.core.dao.DataInfoMapper;
import com.sciencep.pro.core.domain.dto.project.DataInfoTO;
import com.sciencep.pro.core.domain.entity.DataInfo;
import com.sciencep.pro.core.service.IDataInfoService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Sciencep
 */
@Service
public class DataInfoServiceImpl extends ServiceImpl<DataInfoMapper, DataInfo> implements IDataInfoService {

    @Override
    public List<DataInfoTO> getDataInfoList() {

        List<DataInfo> dataInfoList = this.list(new LambdaQueryWrapper<DataInfo>().eq(DataInfo::getIsDel, Constant.IsDelete.NO).orderByDesc(DataInfo::getCreateDate));
        if (CollUtil.isEmpty(dataInfoList)) {
            return new ArrayList<>();
        }
        List<DataInfoTO> result = new ArrayList<>();
        dataInfoList.forEach(o ->
                result.add(new DataInfoTO().setDataId(String.valueOf(o.getId())).setDataName(o.getDataName()).setCreateUserName(o.getCreateUserName())
                        .setCreateDate(o.getCreateDate()).setMustFlag(o.getMustFlag()))
        );

        return result;
    }
}
